package com.digital.smartgrow.controller.datacenter;


import com.digital.smartgrow.common.advice.Result;
import com.digital.smartgrow.dto.datacenter.LearnExperiencePageDTO;
import com.digital.smartgrow.entity.datacenter.LearnExperience;
import com.digital.smartgrow.service.datacenter.LearnExperienceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学历经历 前端控制器
 * </p>
 *
 * @author xiewb
 * @since 2022-04-04
 */
@Api(tags = "学历经历")
@RestController
@RequestMapping("${context.prefix}/learnExperience")
public class LearnExperienceController {

    @Autowired
    private LearnExperienceService learnExperienceService;

    @ApiOperation(value = "列表分页查询")
    @PostMapping("/getListByPage")
    public Object getListByPage(@RequestBody LearnExperiencePageDTO learnExperiencePageDTO) {
        return learnExperienceService.getListByPage(learnExperiencePageDTO);
    }

    @ApiOperation(value = "学历经历详情")
    @GetMapping("/getInfo")
    public Object getInfo(Integer id) {
        if (id == null) return Result.fail("id不能为空");
        return learnExperienceService.getInfo(id);
    }

    @ApiOperation(value = "学历经历-删除")
    @GetMapping("/removeById")
    public Object removeById(Integer id) {
        if (id == null) return Result.fail("id不能为空");
        return learnExperienceService.removeById(id);
    }

    @ApiOperation(value = "学历经历-新增")
    @PostMapping("/add")
    public Object add(@Valid @RequestBody LearnExperience learnExperience) {
        return learnExperienceService.save(learnExperience);
    }

    @ApiOperation(value = "学历经历-编辑")
    @PostMapping("/edit")
    public Object edit(@Valid @RequestBody LearnExperience learnExperience) {
        if (learnExperience == null || learnExperience.getId() == null) return Result.fail("id不能为空");
        return learnExperienceService.updateById(learnExperience);
    }
}
